﻿namespace GameStudio.Framework.GraphicsEngine
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using SlimDX;
    using SlimDX.Direct3D9;

    public class Camera : VisualObjectBase
    {
        #region Fields

        private Matrix _projectionMatrix;

        #endregion Fields

        #region Methods

        /// <summary>
        /// Initilizes this instance.
        /// </summary>
        public override void Initilize()
        {
            this.Matrix = Matrix.LookAtLH(new Vector3(0, 0.0f, -1f), new Vector3(0, 0.0f, 100f), new Vector3(0, 1, 0));

            _projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 10.0f);
        }

        /// <summary>
        /// Renders this instance.
        /// </summary>
        public override void Render()
        {
            // Render the camera with its changed position

            DeviceContext.Current.Device.SetTransform(TransformState.View, this.Matrix);
            DeviceContext.Current.Device.SetTransform(TransformState.Projection, _projectionMatrix);

            // reset the camera poistion after rendering , can be removed in case the camera will remove based on mouse/keyboard position
            //this.Matrix = Matrix.LookAtLH(new Vector3(0, 0.0f, -1f), new Vector3(0, 0.0f, 100f), new Vector3(0, 1, 0));

        }

        #endregion Methods
    }
}